<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="com.meila.cms.entity.User"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

User u=((User) session.getAttribute("loginUser"));
%>

<!DOCTYPE HTML>
<html lang="zh-CN">
  <head>
    <base href="<%=basePath%>">
    
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    
    <title>账户设置</title>
    
    <jsp:include page="../common/common.jsp"></jsp:include>
    
    
  </head>
  
  <body class="client-body updatePassContent-active">
  	<jsp:include page="../common/client-head.jsp"></jsp:include>
	<script src="<%=request.getContextPath() %>/resources/js/system/index/jquery.md5.js"></script>
	<script src="<%=request.getContextPath() %>/resources/js/ajaxfileupload.js"></script>
	<script src="<%=request.getContextPath() %>/resources/js/My97DatePicker/WdatePicker.js"></script>
	<script src="<%=request.getContextPath() %>/resources/js/system/account/updatePassContent.js"></script>
    
  	<div class="client-content">
  		<jsp:include page="../common/client-leftMenu-setting.jsp"></jsp:include>
  	
  		<div class="client-contentBox">
  			<div id="as-title" class="as-title clearfix">
  				<a id="" data-page="baseContent" class="a-black baseBtn" href="front/setting/accountSet">基本资料</a>
  				<a id="" data-page="approveContent" class="a-black approveBtn" href="front/setting/approveContent">认证资料</a>
  				<a id="" data-page="updatePassContent" class="a-black updatePassBtn" href="front/setting/updatePassContent">修改密码</a>
  			</div>
			
			<!-- 修改密码 -->
  			<form id="updatePassContent" class="form-horizontal as-formBox as-formBox2" style="display: block;">
			  <div class="form-group">
			    <label class="col-sm-3 control-label">原始密码</label>
			    <div class="col-xs-9">
			    	 <input type="hidden" id="phoneno" value="${phone}">
			     	 <input type="password" id="oldpassword" name="oldpassword" class="form-control" />
			    </div>
			  </div>
			  
			  <div class="form-group">
			    <label class="col-sm-3 control-label">新密码密码</label>
			    <div class="col-xs-9">
			     	 <input type="password" id="newpassword" name="newpassword" class="form-control" />
			    </div>
			  </div>
			  
			  <div class="form-group">
			    <label class="col-sm-3 control-label">确认新密码</label>
			    <div class="col-xs-9">
			     	 <input type="password" id="checkpassword" name="checkpassword" class="form-control" />
			    </div>
			  </div>
			  
			  <div class="form-group">
			    <div class="col-sm-offset-3 col-sm-9">
			      <button type="submit" id="update" class="btn btn2 a-white as-formStyle3">修改</button>
			    </div>
			  </div>
			  
			  <div id="error3" class="error-resgister">
					<span id="errorContent3"></span><!-- 错误提示 -->
			  </div>
			</form>
			
  		</div><!-- as-content -->
  	</div><!-- client-content -->
	
  	<script type="text/javascript">
	    function updatePwd(){
	    	$("#update").click(function(){
	    		var oldpassword=$("#oldpassword").val();
	    		var newpassword=$("#newpassword").val();
	    		var checkpassword=$("#checkpassword").val();
	    		
	    		var pwd=/(?!^[0-9]+$)(?!^[A-z]+$)(?!^[^A-z0-9]+$)^.{6,16}$/;  //6~16位字符，至少包含数字.字母.符号中的2种
	    		
	    		if(oldpassword=="" || newpassword=="" || checkpassword==""){
	    			$("#error3").css("display","block");
					$("#errorContent3").text("您所填信息不完整！");
					return false;
	    		}else if(!pwd.test(newpassword)){
	    			$("#error3").css("display","block");
					$("#errorContent3").text("密码必须是6-16位，至少包含数字.字母.符号中的2种！");
					return false;
	    		}else if(newpassword==oldpassword){
	    			$("#error3").css("display","block");
					$("#errorContent3").text("新旧密码不能相同！");
					return false;
	    		}else if(checkpassword!=newpassword){
	    			$("#error3").css("display","block");
					$("#errorContent3").text("您两次输入的密码不一致！");
					return false;
	    		}else{
	    			$("#errorContent3").text("");
	    			upPwd();	
	    		}
	    	});
	    }
	    
	    function upPwd(){
	    	$.ajax({
	    		type:'post',
	    		url:CONTEXT_PATH+'front/setting/updatePwd',/* +$("#phone").val() */
	    		data: {"phone":$("#phoneno").val(),"opassword":$.md5($("#oldpassword").val()),"npassword":$.md5($("#newpassword").val())},
	    		async: false,
	    		success:function(data){
					if(data.flag){
						alert(data.message);
					}else{
						alert(data.message);
					}
	    		}
	    	});
	    }
	</script>
	
  </body>
</html>
